Telegram Group & Telegram Channel
🧠 Задача на Go (1.22+)


package main

import "fmt"

func main() {
m = map[string]int{"a": 1, "b": 2, "c": 3}

defer fmt.Println("done")

for k, v := range m {
defer fmt.Println(k, v)
}
}


Что выведет этот код?

A.
c 3
b 2
a 1
done

B.
done
a 1
b 2
c 3

C.
done
c 3
b 2
a 1

D.
a 3
a 3
a 3
done

Почему A? — в Go 1.22 range-переменные k и v создаются на каждом шаге заново, а defer захватывает копии, не ссылки.



tg-me.com/golangtests/770
Create:
Last Update:

🧠 Задача на Go (1.22+)


package main

import "fmt"

func main() {
m = map[string]int{"a": 1, "b": 2, "c": 3}

defer fmt.Println("done")

for k, v := range m {
defer fmt.Println(k, v)
}
}


Что выведет этот код?

A.
c 3
b 2
a 1
done

B.
done
a 1
b 2
c 3

C.
done
c 3
b 2
a 1

D.
a 3
a 3
a 3
done

Почему A? — в Go 1.22 range-переменные k и v создаются на каждом шаге заново, а defer захватывает копии, не ссылки.

BY Go tests


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/golangtests/770

View MORE
Open in Telegram


Go tests Telegram | DID YOU KNOW?

Date: |

What is Telegram?

Telegram’s stand out feature is its encryption scheme that keeps messages and media secure in transit. The scheme is known as MTProto and is based on 256-bit AES encryption, RSA encryption, and Diffie-Hellman key exchange. The result of this complicated and technical-sounding jargon? A messaging service that claims to keep your data safe.Why do we say claims? When dealing with security, you always want to leave room for scrutiny, and a few cryptography experts have criticized the system. Overall, any level of encryption is better than none, but a level of discretion should always be observed with any online connected system, even Telegram.

Go tests from ms


Telegram Go tests
FROM USA